package com.xxx.common;

import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public Result() {
    }

    public Result(Integer code,String message) {
        this.code=code;
        this.message=message;
    }

    public Result(Integer code,String message,T data) {
        this.code=code;
        this.message=message;
        this.data=data;
    }

    public static <T> Result<T> success(String message){
        Result<T> tApiResponse = new Result<>();
        tApiResponse.setCode(Code.SUCCESS_OK);
        tApiResponse.setMessage(message);
        return tApiResponse;
    }

    public static <T> Result<T> success(String message,T data){
        Result<T> tApiResponse = new Result<>();
        tApiResponse.setCode(Code.SUCCESS_OK);
        tApiResponse.setMessage(message);
        tApiResponse.setData(data);
        return tApiResponse;
    }
    public static <T> Result<T> error(Integer code,String message){
        Result<T> tApiResponse = new Result<>();
        tApiResponse.setCode(code);
        tApiResponse.setMessage(message);
        return tApiResponse;
    }

    public static <T> Result<T> error(String message){
        Result<T> tApiResponse = new Result<>();
        tApiResponse.setCode(Code.ERROR);
        tApiResponse.setMessage(message);
        return tApiResponse;
    }
}
